home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / portsn1a / portfind.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-10-04  |  7.5 KB  |  266 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form frmPortFind 
  4.    BorderStyle     =   4  'Fixed ToolWindow
  5.    Caption         =   "Port Finder"
  6.    ClientHeight    =   2220
  7.    ClientLeft      =   45
  8.    ClientTop       =   285
  9.    ClientWidth     =   3255
  10.    Icon            =   "portfind.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2220
  15.    ScaleWidth      =   3255
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   2  'CenterScreen
  18.    Visible         =   0   'False
  19.    Begin VB.CommandButton Command1 
  20.       Caption         =   "Start"
  21.       Height          =   495
  22.       Left            =   2280
  23.       TabIndex        =   0
  24.       Top             =   120
  25.       Width           =   855
  26.    End
  27.    Begin VB.CheckBox Check1 
  28.       Caption         =   "Stop After First Find"
  29.       Height          =   195
  30.       Left            =   120
  31.       TabIndex        =   11
  32.       Top             =   1560
  33.       Width           =   1695
  34.    End
  35.    Begin VB.TextBox Text4 
  36.       Height          =   285
  37.       Left            =   960
  38.       TabIndex        =   10
  39.       Text            =   "5"
  40.       Top             =   1200
  41.       Width           =   375
  42.    End
  43.    Begin VB.TextBox Text2 
  44.       Height          =   285
  45.       Left            =   1080
  46.       TabIndex        =   4
  47.       Top             =   480
  48.       Width           =   375
  49.    End
  50.    Begin VB.TextBox Text3 
  51.       Height          =   285
  52.       Left            =   1800
  53.       TabIndex        =   6
  54.       Top             =   480
  55.       Width           =   375
  56.    End
  57.    Begin VB.OptionButton Option2 
  58.       Caption         =   "Try Ports"
  59.       Height          =   255
  60.       Left            =   120
  61.       TabIndex        =   8
  62.       Top             =   480
  63.       Value           =   -1  'True
  64.       Width           =   1095
  65.    End
  66.    Begin VB.OptionButton Option1 
  67.       Caption         =   "Try All Ports (1-32767)"
  68.       Height          =   255
  69.       Left            =   120
  70.       TabIndex        =   7
  71.       Top             =   840
  72.       Width           =   1935
  73.    End
  74.    Begin MSWinsockLib.Winsock sock 
  75.       Left            =   1560
  76.       Top             =   1080
  77.       _ExtentX        =   741
  78.       _ExtentY        =   741
  79.       _Version        =   327681
  80.    End
  81.    Begin VB.TextBox Text1 
  82.       Height          =   285
  83.       Left            =   960
  84.       TabIndex        =   2
  85.       Top             =   120
  86.       Width           =   1215
  87.    End
  88.    Begin VB.Label Label3 
  89.       Caption         =   "Wait (sec):"
  90.       Height          =   255
  91.       Left            =   120
  92.       TabIndex        =   9
  93.       Top             =   1200
  94.       Width           =   855
  95.    End
  96.    Begin VB.Label Label4 
  97.       Caption         =   "to"
  98.       Height          =   255
  99.       Left            =   1560
  100.       TabIndex        =   5
  101.       Top             =   480
  102.       Width           =   255
  103.    End
  104.    Begin VB.Label Label1 
  105.       Caption         =   "Search IP:"
  106.       Height          =   255
  107.       Left            =   120
  108.       TabIndex        =   3
  109.       Top             =   120
  110.       Width           =   855
  111.    End
  112.    Begin VB.Label Label2 
  113.       BackStyle       =   0  'Transparent
  114.       BorderStyle     =   1  'Fixed Single
  115.       Caption         =   "No Connections"
  116.       Height          =   255
  117.       Left            =   120
  118.       TabIndex        =   1
  119.       ToolTipText     =   "Click For All Info"
  120.       Top             =   1920
  121.       Width           =   3015
  122.    End
  123. Attribute VB_Name = "frmPortFind"
  124. Attribute VB_GlobalNameSpace = False
  125. Attribute VB_Creatable = False
  126. Attribute VB_PredeclaredId = True
  127. Attribute VB_Exposed = False
  128. Public NumWait As Integer    'how many secs to wait for response
  129. Public UpperB As Integer
  130.  Const HWND_TOP = 0
  131.  Const HWND_TOPMOST = -1
  132.  Const HWND_NOTOPMOST = -2
  133.  Const SWP_NOMOVE = &H2
  134.  Const SWP_NOSIZE = &H1
  135.  Const flags = SWP_NOMOVE Or SWP_NOSIZE
  136. Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  137. Dim LowerB As Integer
  138. Dim PortFound As Boolean
  139. Dim StopSrch As Boolean
  140. Dim FirstRun As Boolean
  141. Dim StopIt As Boolean
  142. Sub stayontop(the As Form)
  143. SetWinOnTop = SetWindowPos(the.hWnd, HWND_TOPMOST, 0, 0, 0, 0, flags)
  144. End Sub
  145. Private Sub Command1_Click()
  146. If sock.State <> 0 Then
  147.     sock.Close
  148.     Do Until sock.State = 0
  149.         DoEvents
  150.     Loop
  151. End If
  152. If Command1.Caption = "Start" Then
  153.     Command1.Caption = "Stop"
  154. PortFound = False
  155. FirstRun = True
  156. If Check1.Value = 1 Then
  157.     StopSrch = True
  158.     StopSrch = False
  159. End If
  160. If Option2.Value = True Then
  161.     If Text2.Text <> "" And Text3.Text <> "" Then
  162.         UpperB = Int(Val(Text3.Text))
  163.         LowerB = Int(Val(Text2.Text))
  164.     Else
  165.         MsgBox "Must Specify Ports To Find", vbExclamation + vbMsgBoxSetForeground + vbOKOnly, "Port Finder"
  166.     End If
  167. ElseIf Option1.Value = True Then
  168.     UpperB = 32767
  169.     LowerB = 1
  170. End If
  171. If Text4.Text = "" Then
  172.     Text4.Text = "5"
  173. End If
  174. NumWait = Int(Val(Text4.Text))
  175. Label2.Caption = "Scanning Ports..."
  176. sock.RemoteHost = Text1.Text
  177. sock.LocalPort = 0
  178. For qw% = LowerB To UpperB
  179.     If StopIt = True Then
  180.           Command1.Caption = "Start"
  181.           Label2.Caption = "Canceled...No Connections"
  182.           StopIt = False
  183.             Exit Sub
  184.     End If
  185.     sock.Connect sock.RemoteHost, qw%
  186.     start = 0
  187.     start = (Timer)
  188.     Do Until sock.State = 7
  189.         If StopIt = True Then
  190.             Command1.Caption = "Start"
  191.             Label2.Caption = "Canceled...No Connections"
  192.               StopIt = False
  193.             Exit Sub
  194.         End If
  195.         DoEvents
  196.         If (Timer) - (start) >= NumWait Then
  197.             sock.Close
  198.             Do Until sock.State = 0
  199.                 DoEvents
  200.                 If StopIt = True Then
  201.                     Command1.Caption = "Start"
  202.                     Label2.Caption = "Canceled...No Connections"
  203.                     StopIt = False
  204.                     Exit Sub
  205.                 End If
  206.             Loop
  207.             Exit Do
  208.         End If
  209.     Loop
  210.     If sock.State = 7 Then
  211.         If FirstRun = True Then
  212.             Label2.Caption = "Open port found: " & qw%
  213.         Else
  214.             Label2.Caption = Label2.Caption & ", " & qw%
  215.         End If
  216.         PortFound = True
  217.         FirstRun = False
  218.         sock.Close
  219.         Do Until sock.State = 0
  220.             DoEvents
  221.         Loop
  222.         If StopSrch = True Then
  223.                 Exit For
  224.         End If
  225.     End If
  226. Next qw%
  227. If PortFound = False Then
  228.     Label2.Caption = "No Ports Found"
  229. End If
  230. Label2.Caption = Label2.Caption & "  ...Done"
  231.     'stop
  232.     StopIt = True
  233. End If
  234. If Command1.Caption = "Start" Then
  235.     Command1.Caption = "Stop"
  236.     Exit Sub
  237. ElseIf Command1.Caption = "Stop" Then
  238.     Command1.Caption = "Start"
  239. End If
  240. End Sub
  241. Private Sub Command2_Click()
  242. End Sub
  243. Private Sub Form_Activate()
  244. stayontop Me
  245. End Sub
  246. Private Sub Form_Load()
  247. StopIt = False
  248. sock.Protocol = sckTCPProtocol
  249. Me.Visible = True
  250. stayontop Me
  251. End Sub
  252. Private Sub Form_Resize()
  253. stayontop Me
  254. End Sub
  255. Private Sub Form_Unload(Cancel As Integer)
  256. sock.Close
  257. Do Until sock.State = 0
  258.     DoEvents
  259. Cancel = False
  260. End Sub
  261. Private Sub Label2_Click()
  262. MsgBox "" & Label2.Caption & "", vbMsgBoxSetForeground + vbOKOnly, "Port Finder"
  263. End Sub
  264. Private Sub Label5_Click()
  265. End Sub
  266.